package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询接口")
    public ResponseResult<PageResponse<NursingProjectVo>> queryPage(
            @ApiParam(value = "姓名") String name,
            @ApiParam(value = "当前页") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页展示条数") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态") Integer status) {
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.queryPage(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult addNursingProject(@ApiParam(value = "添加护理项目信息") @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getNursingProjectById(@PathVariable("id") Integer id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getNursingProjectById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult updateStatusById(@PathVariable(value = "id") Integer id, @PathVariable(value = "status") Integer status) {
        nursingProjectService.updateStatusById(id, status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult deleteNursingProjectById(@PathVariable(value = "id") Integer id) {
        nursingProjectService.deleteNursingProjectById(id);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> showAllNursingProject() {
        List<NursingProjectVo> nursingProjectVoList = nursingProjectService.showAllNursingProject();
        return success(nursingProjectVoList);
    }
}
